package com.cn.wx.servlet;

import com.cn.wx.model.NavModel;
import com.cn.wx.model.NewsModel;
import com.cn.wx.model.NewsPlateModel;
import com.cn.wx.model.TopModel;
import com.cn.wx.service.NewsPlateService;
import com.cn.wx.service.NewsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/news")
public class NewsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        TopModel topModel = new TopModel();
        List<NavModel> list = topModel.getNavList();
//显示头部内容
        req.setAttribute("topModel", topModel);
        req.setAttribute("list", list);
//        显示新闻内容
//        1.查询新闻栏目板块
        NewsPlateService newsPlateService = new NewsPlateService();
        List<NewsPlateModel> newsPlateModelList = newsPlateService.findAll();

//        2.查询新闻内容
        NewsService newsService=new NewsService();
        List<NewsModel> newsModelList=newsService.getAll(10,1);
        req.setAttribute("newsModelList",newsModelList);

        req.getRequestDispatcher("/jsp/news.jsp").forward(req, resp);
    }
}
